import request from '@/utils/request'

// 获取书籍分类
export function getClassify() {
  return request({
    url: '/api/classify',
    method: 'get',
  })
}

// 保存书籍
export function saveBook(data){
  return request({
    url: '/api/book',
    data: data,
    method: 'post',
  })
}

// 获取所有图书

export function getAllBook(query={}){
  let queryStr = ''
  for(let key of Object.keys(query)){
    queryStr+= key + '='+ query[key] + '&'
  }
  queryStr = queryStr.slice(0,-1)
  return  request({
    url: `/api/getAllbook?${queryStr}`,
    method: 'get',
  })
}

// 更新书籍

export function updateBook(id,data) {
  return  request({
    url: '/api/book?id='+id,
    method: 'put',
    data
  })
}

// 上传书籍

export function uploadBookToServer(data) {
  return request({
    url: '/api/uploadBook',
    method: 'post',
    data,
    headers: {'Content-Type':'multipart/form-data'}
  })
}


// 根据书籍名字，模糊查询书籍

export function getBooksByName(bookName) {
  return request({
    url: '/api/getBooksByName?bookName='+bookName,
    method: 'get',
  })
}